package com.chb.system.controller.apis;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.chb.system.annotation.OperLogAnnotation;
import com.chb.system.service.MenuService;
import com.chb.system.service.UserService;
import com.chb.system.vo.MenuVo;
import com.hos.entity.sys.Menu;
import com.hos.entity.sys.Role;
import com.hos.entity.sys.User;
import com.hos.utils.WebUtil;
import com.hos.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 陈海彬
 * @date: Created in 2023/12/8 16:54
 * @description:
 * @modified By:
 * @version:
 */
@RestController
@RequestMapping("/system/api/menu")
@Api(value = "左侧菜单相关接口")
public class APIMenuController {

    @Autowired
    private MenuService menuService;


    @GetMapping("/getLeftMenu")
    @ApiOperation(value = "获取左侧菜单数据")
    public Result<List<Menu>> getLeftMenu() {
        return new Result<>(200, "获取左侧菜单成功", menuService.getLeftMenu());
    }

    @GetMapping("/selectAllMenu")
    @ApiOperation(value = "获取所有的菜单信息")
    public Result<List<Menu>> selectAllMenu() {
        return new Result<>(200, "查询成功", menuService.selectAllMenu());
    }

    @PostMapping("findMuneByCond")
    @ApiOperation(value = "条件查询菜单信息")
    public Result<List<Menu>> findMuneByCond(@RequestBody MenuVo menuVo) {
        return new Result<>(200, "请求成功", menuService.findMuneByCond(menuVo));
    }

    @PostMapping("/addMenu")
    @ApiOperation(value = "添加菜单")
    @OperLogAnnotation(business_type = "系统业务-增加菜单", operator_type = 1)
    public Result<Integer> addMenu(Menu menu) {
        return new Result<>(200, "添加成功", menuService.addMenu(menu));
    }

    @DeleteMapping("deleteMenuById/{id}")
    @ApiOperation(value = "根据菜单ID永久删除菜单")
    @OperLogAnnotation(business_type = "系统业务-删除菜单", operator_type = 1)
    public Result<Integer> deleteRoleByRoleId(@PathVariable Long id) {
        return new Result<>(200, "删除成功", menuService.deleteMenuById(id));
    }

    @PostMapping("/getMenuByMenuId/{menuId}")
    @ApiOperation(value = "根据菜单Id查询到一个菜单")
    public Result<Menu> getRoleByRoleId(@PathVariable Long menuId) {
        return new Result<Menu>(200, "查询成功", menuService.getMenuById(menuId));
    }

    @PostMapping("updateMenu")
    @ApiOperation(value = "修改菜单信息")
    @OperLogAnnotation(business_type = "系统业务-修改菜单", operator_type = 1)
    public Result updateMenu(@RequestBody Menu menu) {
        return new Result<>(200, "修改成功", menuService.updateMenu(menu));
    }


}